<?php
class UserCollectAction extends UAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'uindex';
		$this->data['menu']	= 'collect';
	}
	
	public function execute()
	{
		$page = $this->getPage();
		$pageSize = 10;
		$collectService  = new BaseDbService('collect');
		$where 			= array('user_id'=>'eq:'.$this->user_id);
		$result			= $collectService->getList($where,  'id DESC', ($page-1)*$pageSize, $pageSize, array('share_id'));
		$totalNum 		= $result['count'];
		$rows			= $result['rows'];
		$share_ids		= array();
		if ($rows)
		{
			foreach($rows as $k=>$v)
			{
				$share_ids[$v['share_id']] = $v['share_id'];
			}
		}
		
		if ($share_ids)
		{
			$shareService  	= new ShareService();
			$con = array(
				'shareids'=>join(',', $share_ids),
			);
			$result 	= $shareService->query($con, $page, $pageSize);
			//$totalNum 	= $result['totalNum'];
			$this->data['column'] = $result['list'];
			
			$result		=	$shareService->getListByIds($share_ids);
			foreach($this->data['column'] as $sk=>$share){
				foreach($share as $k=>$item){
					$share[$k]['collect_num'] = (int)$result[$item['share_id']]['collect_num'];
					$share[$k]['comment_num'] = (int)$result[$item['share_id']]['comment_num'];
				}
				$this->data['column'][$sk] = $share;
			}
			
		}
		
		
		$ltConfig		= C('LtConfig');
		$pagerConfig	= $ltConfig->get('pagination.pager');
		$baseUrl 		= C('LtUrl')->generate('Default', 'Index', array('module'=>'User','action'=>'Collect','uid'=>$this->user_id,'p' => ':page'));
		$pagination 	= new PiscesPagination;
		$pagination->init($pagerConfig);
		$this->data['pages'] = $pagination->pager($page, $totalNum, $baseUrl);
		$this->data['items'] = $rows;
		
	}
}

